package view;

import java.awt.Image;
import java.util.ArrayList;

import javax.swing.ImageIcon;

import common.*;
import enums.Avatar;

import view.component.BackGroundPanel;
import view.component.GameFrame;


public class MainFrame {
	
	private BackGroundPanel backGroundPanel;
	private GameFrame mainFrame;
	
	private SingleGamePanel singleGamePanel;
	private FriendsPanel friendsPanel;
	private MultiGamePanel multiGamePanel;
	private OptionPanel optionPanel;
	private RankingPanel rankingPanel;
	private SelectPropPanel selectPropPanel;
	private RoomPanel roomPanel;
	private LoginPanel loginPanel;
	private RegisterPanel registerPanel;
	private SettingsPanel settingsPanel;
	
	private void initialFrame(){
		mainFrame = new GameFrame();
		
		backGroundPanel = new BackGroundPanel();
		backGroundPanel.setBounds(21,41,1000,700);
		backGroundPanel.setAlpha(1.0f);
		Image img = new ImageIcon("images/blackboard3.jpg").getImage();
		backGroundPanel.setImage(img);
		mainFrame.getContentPane().add(backGroundPanel);
		
		singleGamePanel = new SingleGamePanel();
		singleGamePanel.setMainFrame(this);
		backGroundPanel.add(singleGamePanel);
		
		friendsPanel = new FriendsPanel();
		friendsPanel.setMainFrame(this);
		backGroundPanel.add(friendsPanel);
		
		multiGamePanel = new MultiGamePanel();
		multiGamePanel.setMainFrame(this);
		backGroundPanel.add(multiGamePanel);
		
		optionPanel = new OptionPanel();
		optionPanel.setMainFrame(this);
		backGroundPanel.add(optionPanel);
		
		rankingPanel = new RankingPanel();
		rankingPanel.setMainFrame(this);
		backGroundPanel.add(rankingPanel);

		selectPropPanel = new SelectPropPanel();
		selectPropPanel.setMainFrame(this);
		backGroundPanel.add(selectPropPanel);
		
		roomPanel = new RoomPanel();
		roomPanel.setMainFrame(this);
		backGroundPanel.add(roomPanel);
		
		loginPanel = new LoginPanel();	
		loginPanel.setMainFrame(this);
		backGroundPanel.add(loginPanel);
		
		registerPanel = new RegisterPanel();	
		registerPanel.setMainFrame(this);
		backGroundPanel.add(registerPanel);
		
		settingsPanel = new SettingsPanel();
		settingsPanel.setMainFrame(this);
		backGroundPanel.add(settingsPanel);
		
		mainFrame.setVisible(true);
	}
	
	public void changePanel(String panelName){
		if(panelName.equals("FriendsPanel")){
			friendsPanel.setVisible(true);
			friendsPanel.fadeIn();
		}else if(panelName.equals("MultiGamePanel")){
			multiGamePanel.setVisible(true);
		}else if(panelName.equals("OptionPanel")){
			optionPanel.setVisible(true);
			optionPanel.fadeIn();
		}else if(panelName.equals("RankingPanel")){
			rankingPanel.setVisible(true);
		}else if(panelName.equals("SelectPropPanel")){
			selectPropPanel.setVisible(true);
		}else if(panelName.equals("SingleGamePanel")){
			singleGamePanel.setVisible(true);
			singleGamePanel.startGame();
		}else if(panelName.equals("RoomPanel")){
			roomPanel.setVisible(true);
		}else if(panelName.equals("LoginPanel")){
			loginPanel.setVisible(true);
			loginPanel.fadeIn();
		}else if(panelName.equals("RegisterPanel")){
			registerPanel.setVisible(true);
			registerPanel.fadeIn();
		}else if(panelName.equals("SettingsPanel")){
			settingsPanel.setVisible(true);
			settingsPanel.fadeIn();
		}
	}
	
	public static void main(String[] args){
		MainFrame m = new MainFrame();
		m.initialFrame();
		m.loginPanel.setVisible(true);
		m.loginPanel.fadeIn();
		ArrayList<Friend> f = new ArrayList<Friend>();
		for(int i=0;i<20;i++){
			Friend f1 = new Friend("abc","abc",Avatar.hokain1,10,true);
			f.add(f1);
		}
		m.friendsPanel.showFriendsList(f);
	}
}
